package com.zpark.controller;

import com.zpark.entity.User;
import com.zpark.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    UserMapper userMapper; //注入mapper层

    //根据id查询，查询单个
    @RequestMapping("/hello/{id}")
    @ResponseBody
    public User hello(@PathVariable("id") Integer id){
        User user = userMapper.findById(id).get(); //jpa自带查询方法
        return  user;
    }

    //查询全部
    @RequestMapping("/findAll")
    @ResponseBody
    public List<User> findAll(){
        List<User> list =userMapper.findAll();//jpa自带查询方法
        return  list;
    }

}